package testes;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import models.beans.Aeroporto;
import persistence.DAO;

@ManagedBean
@RequestScoped
public class TestaBD {
	private DAO dao;
	private Connection con;
	private PreparedStatement pstmt;
	
	public TestaBD() {
		dao = DAO.getInstance();
		con = this.dao.getConnection();
	}

	
	public List<Aeroporto> getAeroportos() {
		List<Aeroporto> lista = null;
		try {
			pstmt = con.prepareStatement("SELECT * FROM Aeroporto");
			
			ResultSet rs = pstmt.executeQuery();
			lista = new LinkedList<Aeroporto>();
			while(rs.next()){
				Aeroporto a = new Aeroporto();
				a.setNome(rs.getString(3));
				a.setPais(rs.getString(4));
				
				lista.add(a);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return lista;
	}
	
}
